package com.meituan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.meituan.mapper.GoodsMapper;
import com.meituan.model.GoodsEntity;
import com.meituan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;
    @Override
    public List<GoodsEntity> findByShopId(String shopId) {
        return goodsMapper.findByShopId(shopId);
    }

    @Override
    public Integer save(GoodsEntity goodsEntity) {
        return goodsMapper.save(goodsEntity);
    }

    @Override
    public PageInfo<GoodsEntity> findPageByShopIdWithClassify(String shopId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsEntity> list =goodsMapper.findPageByShopIdWithClassify(shopId);
        PageInfo<GoodsEntity> pageInfo = new PageInfo<GoodsEntity>(list);
        return pageInfo;
    }

    @Override
    public Integer delGoods(String goodsId) {
        return goodsMapper.delGoods(goodsId);
    }

    @Override
    public Integer editGoods(GoodsEntity goodsEntity) {
        return goodsMapper.updateGoods(goodsEntity);
    }

    @Override
    public List<GoodsEntity> findByClassifyId(String GoodsClassifyId) {
        return goodsMapper.findByClassifyId(GoodsClassifyId);
    }

    @Override
    public Integer updateGoodsImg(String goodsImg, String goodsId) {
        return goodsMapper.updateImg(goodsImg,goodsId);
    }
}
